/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package me.everdras.WordFilter;

import java.io.*;


/**
 *
 * @author Josh
 */
public class Porter {
    
    private File target;
    private FileOutputStream fos;
    private ObjectOutputStream oos;
    private FileInputStream fis;
    private ObjectInputStream ois;
    
    public Porter(String tarfile) {
        
        target = new File(tarfile);
        fos = null;
        oos = null;
        fis = null;
        ois = null;
        
    }
    
    public boolean primeOutput() {
        
        try {
            fos = new FileOutputStream(target);
            oos = new ObjectOutputStream(fos);
        } catch (Exception ex) { return false; }
        return true;
        
    }
    
    public boolean primeInput() {
        try {
            fis = new FileInputStream(target);
            ois = new ObjectInputStream(fis);
        } catch (Exception ex) { return false; }
        return true;
    }
    
    public boolean output(Object o) {
        try {
            oos.writeObject(o);
        }
        catch(Exception e) {return false;}
        return true;
    }
    
    public Object input() {
        Object o = null;
        
        try {
            o = ois.readObject();
        }
        catch(Exception e) { }
        
        return o;
    }
    
    public void close() {
        try {
            if(oos != null)
                oos.close();
            
            if(ois != null)
                ois.close();
            
            if(fos != null) 
                fos.close();
            
            if(fis != null) 
                fis.close();
        } catch (IOException ex) {}
        
    }
    
    public String getPath() {
        return target.toString();
    }
    
    
}
